<?php
/****************************************************************************

	COPYRIGHT(C) WWW.MAXSI.DK, MAXSI SOFTWARE, SORTIE 2009
	ALL RIGHTS RESERVED

	Maxsi Distribution Shared/ Branch
	Scripts shared by the MasterServer/ and ContentServer/ Branch of the Maxsi
	Distribution Server-Side Code Branches.
		
	MaxsiDataContainer.php
	A binary-safe text-based data container.
	
****************************************************************************/

$mdc_Leader		=	'';
$mdc_LastVar	=	'';

if ( md_IsOutputMDC() )
{
	// Ensure that PHP will NOT accidentally break the protocol by
	// outputting random error messages!
	error_reporting(0);

	function	mdc_SetLeader($NewLeader)
	{
		global	$mdc_Leader;
		$mdc_Leader		=	$NewLeader;
	}
	
	function	mdc_GetLeader()
	{
		global	$mdc_Leader;
		return	$mdc_Leader;
	}
	
	function	mdc_SendVariableTextFull($VariableName,$Data)
	{
		global	$mdc_Leader;
		echo mdc_GetLeader() . $VariableName . chr(0);
		echo strlen($Data) . chr(0);
		echo $Data;
	}
	
	function	mdc_SendVariableTextPartial($VariableName,$Data)
	{
		global	$mdc_Leader;
		echo '!' . mdc_GetLeader() . $VariableName . chr(0);
		echo strlen($Data) . chr(0);
		echo $Data;
	}
	
	function	mdc_SendVariableTextFinal($VariableName,$Data)
	{
		global	$mdc_Leader;
		echo mdc_GetLeader() . $VariableName . chr(0);
		echo strlen($Data) . chr(0);
		echo $Data;
	}
	
	function	mdc_SendVariableFinal($VariableName)
	{
		echo mdc_GetLeader() . $VariableName . chr(0);
		echo '0' . chr(0);
	}
	
	function	mdc_SendVariableHeader($VariableName,$DataLen)
	{
		global	$mdc_Leader;
		echo mdc_GetLeader() . $VariableName . chr(0);
		echo $DataLen . chr(0);
	}
	
	function	mdc_SendError($Error)
	{
		mdc_SendVariableTextFull('Error',$Error);		
	}
	
	function	mdc_SendErrorDie($Error)
	{
		mdc_SendVariableTextFull('Error',$Error);
		die();		
	}
	
	
	function	mdc_SendInfo($Info)
	{
		mdc_SendVariableTextFull('Info',$Info);		
	}
}
elseif ( md_IsOutputHTML() )
{
	function	mdc_SetLeader($NewLeader)
	{
		global	$mdc_Leader;
		$mdc_Leader		=	$NewLeader;
	}
	
	function	mdc_GetLeader()
	{
		global	$mdc_Leader;
		return	$mdc_Leader;
	}
	
	function	mdc_SendVariableTextFull($VariableName,$Data)
	{
		global	$mdc_Leader;
		echo '<tr><td style="vertical-align: top;"><b>'.mdc_GetLeader() . $VariableName.': </b></td><td style="vertical-align: top;">'.$Data.'</td></tr>';
	}
	
	function	mdc_SendVariableTextPartial($VariableName,$Data)
	{
		global	$mdc_Leader;
		if ( strcasecmp($mdc_LastVar,$VariableName) != 0 )
		{
			echo '<tr><td style="vertical-align: top;"><b>'.mdc_GetLeader() . $VariableName.': </b></td><td style="vertical-align: top;">';		
		}
		$mdc_LastVar	=	$VariableName;
		echo $Data;
	}
	
	function	mdc_SendVariableTextFinal($VariableName,$Data)
	{
		global	$mdc_Leader;
		$mdc_LastVar	=	'';
		echo $Data.'</td></tr>';;
	}
	
	function	mdc_SendVariableFinal($VariableName)
	{
		global	$mdc_Leader;
		echo '</td></tr>';;
	}
	
	function	mdc_SendVariableHeader($VariableName,$DataLen)
	{
		global	$mdc_Leader;
		echo '<tr><td style="vertical-align: top;"><b>'.mdc_GetLeader() . $VariableName.': </b></td><td style="vertical-align: top;">';
	}
	
	function	mdc_SendError($Error)
	{
		echo 'Error: '.$Error;		
	}
	
	function	mdc_SendErrorDie($Error)
	{
		die('Error: '.$Error);		
	}
	
	function	mdc_SendInfo($Info)
	{
		echo $Info;		
	}
}

?>